package com.panshi.controller;

import com.panshi.entity.AppComment;
import com.panshi.service.CommentService;
import com.panshi.tools.DataResult;
import com.panshi.tools.PageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api("回答评论业务接口")
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("根据回答id查询评论")
    @ApiImplicitParam(name = "answerId", value = "回答id", required = true)
    @GetMapping("a-comment/byAid/{answerId}")
    public DataResult queryCommentByAid(@PathVariable  Integer answerId, PageBean pageBean) {
        return commentService.queryCommentByAid(answerId,pageBean);
    }

    @ApiOperation("根据主键id查询评论")
    @ApiImplicitParam(name = "id", value = "主键id", required = true)
    @GetMapping("a-comment/byId/{id}")
    public DataResult queryCommentById(@PathVariable Integer id, PageBean pageBean){
        return commentService.queryCommentById(id, pageBean);
    }


    @ApiOperation("增加回答评论")
    @ApiImplicitParam(name = "appComment", value = "评论对象", required = true)
    @PostMapping("a-comment/add")
    public DataResult add(@RequestBody  AppComment appComment){
        return commentService.addComment(appComment);
    }

    @ApiOperation("删除回答评论")
    @ApiImplicitParam(name = "appComment", value = "评论对象", required = true)
    @PostMapping("a-comment/delete")
    public DataResult delete(@PathVariable Integer id){
        return commentService.delete(id);
    }

}

